<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人资料</title>
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/profile.css') }}">
</head>
<body>
    <!-- 导航栏 -->
    <nav>
        <ul>
            <li><a href="/">首页</a></li>
            <li><a href="/products">产品</a></li>
            <li><a href="/cart">购物车</a></li>
            <li><a href="/orders">我的订单</a></li>
            <li><a href="/about">关于我们</a></li>
            <li><a href="/contact">联系我们</a></li>
            {% if 'username' in session %}
            <li><a href="/profile">个人资料</a></li>
            <li><a href="/logout">登出</a></li>
            {% else %}
            <li><a href="/login">登录</a></li>
            <li><a href="/register">注册</a></li>
            {% endif %}
        </ul>
    </nav>

    <!-- 主内容 -->
    <div class="main-content">
        {% if 'username' in session %}
        <h2>个人资料</h2>
        <form action="{{ url_for('profile') }}" method="POST" enctype="multipart/form-data">
            <label for="username">用户名:</label>
            <input type="text" id="username" name="username" value="{{ user.username }}" readonly><br>

            <label for="email">电子邮件:</label>
            <input type="email" id="email" name="email" value="{{ user.email }}"><br>

            <label for="phone">电话号码:</label>
            <input type="text" id="phone" name="phone" value="{{ user.phone }}"><br>

            <label for="password">新密码:</label>
            <input type="password" id="password" name="password"><br>

            <label for="avatar">头像:</label>
            <input type="file" id="avatar" name="avatar"><br>
            {% if user.avatar %}
            <img src="data:image/jpeg;base64,{{ user.avatar | b64encode }}" alt="头像" id="profile-avatar"><br>
            {% endif %}

            <button type="submit">更新资料</button>
        </form>
        {% else %}
        <p>请 <a href="/login">登录</a> 以查看您的个人资料。</p>
        {% endif %}
    </div>

    <!-- 页脚 -->
    <footer>
        <p>&copy; 2024 网上商店。保留所有权利。</p>
        <ul>
            <li><a href="/terms">服务条款</a></li>
            <li><a href="/privacy">隐私政策</a></li>
        </ul>
    </footer>

    <script src="{{ url_for('static', filename='js/profile.js') }}"></script>
</body>
</html>
